package com.yatong.service.impl;

import com.yatong.entity.IntentionalCompany;
import com.yatong.dao.IntentionalCompanyDao;
import com.yatong.service.IntentionalCompanyService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * (IntentionalCompany)表服务实现类
 *
 * @author makejava
 * @since 2018-10-29 21:34:29
 */
@Service("intentionalCompanyService")
public class IntentionalCompanyServiceImpl implements IntentionalCompanyService {
    @Resource
    private IntentionalCompanyDao intentionalCompanyDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public IntentionalCompany queryById(Integer id) {
        return this.intentionalCompanyDao.queryById(id);
    }

    /**
     * 查询多条数据
     *
     * @param offset 查询起始位置
     * @param limit 查询条数
     * @return 对象列表
     */
    @Override
    public List<IntentionalCompany> queryAllByLimit(int offset, int limit) {
        return this.intentionalCompanyDao.queryAllByLimit(offset, limit);
    }

    /**
     * 筛选条件查询多条数据
     *
     * @param intentionalCompany
     * @return
     */
    public List<IntentionalCompany> queryAll(IntentionalCompany intentionalCompany,String tuijian){
        List<IntentionalCompany> intentionalCompanies;
        if (tuijian.equals("true"))
           intentionalCompanies = this.intentionalCompanyDao.queryAlltuijian(intentionalCompany);
        else
            intentionalCompanies = this.intentionalCompanyDao.queryAll(intentionalCompany);
        return intentionalCompanies;
    }

    /**
     * 新增数据
     *
     * @param intentionalCompany 实例对象
     * @return 实例对象
     */
    @Override
    public IntentionalCompany insert(IntentionalCompany intentionalCompany) {
        this.intentionalCompanyDao.insert(intentionalCompany);
        return intentionalCompany;
    }

    /**
     * 修改数据
     *
     * @param intentionalCompany 实例对象
     * @return 实例对象
     */
    @Override
    public int update(IntentionalCompany intentionalCompany) {
        if (intentionalCompany.getCompanyState().equals("5")){
            //已签单
        }

        return this.intentionalCompanyDao.update(intentionalCompany);
//        return this.queryById(intentionalCompany.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.intentionalCompanyDao.deleteById(id) > 0;
    }
}